import qs from 'query-string';
// eslint-disable-next-line import/no-cycle
import request, { Method } from '@/utils/axios';

interface loginParams {
  username: string | number;
  password: string;
}

/**
 * 登录
 * @returns
 * @param params
 */
// export function login(params: loginParams) {
//   return request({
//     url: '/passport/user/login',
//     method: Method.POST,
//     needToken: false,
//     data: qs.stringify(params),
//     headers: {
//       'clientType': 'PC',
//       'Content-Type': 'application/x-www-form-urlencoded',
//     },
//   });
// }

export function login(username, password) {
  const data = {
    username,
    password,
  };
  return request({
    url: '/login/user/login',
    needToken: false,
    method: Method.POST,
    data: data,
  });
}

/**
 * 登出
 */
export function logoutUser() {
  return request({
    url: '/passport/user/logout',
    method: Method.POST,
    needToken: true,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  });
}

/**
 * 获取管理员信息
 */
// export function getUserInfo() {
//   return request({
//     url: '/passport/user/info',
//     method: Method.GET,
//     needToken: true,
//   });
// }

export function getUserInfo() {
  return request({
    url: '/login/user/getInfo',
    method: Method.GET,
    needToken: true,
  });
}

/**
 * 保存管理员信息
 */
export function setUserInfo(params: any) {
  return request({
    url: '/passport/user/info',
    method: Method.PUT,
    data: qs.stringify(params),
    needToken: true,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  });
}

/**
 * 刷新token
 */
export function refreshTokenMethod(token: string) {
  return request({
    url: `/passport/login/refresh/${token}`,
    method: Method.GET,
    params: token,
  });
}

/**
 *
 * 个人中心修改密码
 */
export function changePassword(params: any) {
  return request({
    url: `/passport/user/editPassword`,
    method: Method.PUT,
    data: params,
    needToken: true,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}

// 获取门户地址
export function getTongYiSystemUrl() {
  return request({
    url: '/login/user/getTongYiSystemUrl',
    method: Method.GET,
    needToken: false,
  });
}

// 获取多机构
export function tempTokenGetDeptList(data) {
  return request({
    url: '/login/user/tempTokenGetDeptList',
    method: Method.POST,
    data,
  });
}

// 多机构选择登录
export function tempTokenGetToken(data) {
  return request({
    url: '/login/user/tempTokenGetToken',
    method: Method.POST,
    data,
  });
}

// 查询用户拥有的小程序
export function selectUserHaveSmall(data) {
  return request({
    url: '/login/user/selectUserHaveSmall',
    method: Method.POST,
    needToken: true,
    data,
  });
}
// 切换小程序
export function changeSmallApp(data) {
  return request({
    url: '/login/user/changeSmall',
    method: Method.POST,
    needToken: true,
    data,
  });
}
